import AppConstants from "../AppConstants"
import AppUtil from "../AppUtil"
import LayerMgr from "./LayerMgr"


/**
 * @description 顶部事件拦截组件
 * @author mirahs
 * @email 2892727493@qq.com
 */
export default class TopBlock {
    private static _view: cc.Node


    public static show() {
        this.ensure()

        LayerMgr.setLayer(this._view, AppConstants.viewLayer.Top)
        this._view.active = true
    }

    public static hide() {
        if (!this._view || !this._view.isValid) return

        this._view.active = false
    }


    private static ensure() {
        if (this._view && this._view.isValid) return

        this._view = new cc.Node('TopBlock')
        this._view.opacity = 0
        AppUtil.setWidget(this._view)
        this._view.addComponent(cc.BlockInputEvents)
    }
}
